#!/usr/bin/python3
# -*- coding: utf-8 -*-
from Function import *
from RankUtils import *
from program.environ import RankAscending, FilterAfter, tag

# ==========> 盈亏分析器 参数配置 <==========
start_time = '2023-01-10 00:00:00'  # 开始时间
end_time = '2023-02-10 23:00:00'  # 结束时间
compound_name = 'Bias'  # 组合名称
factor = 'Bias'  # 因子名称
time_interval = '1H'  # 持仓周期
factor_param = 100  # 因子参数
top = 50  # 盈亏排名前N分析
symbol = 'GALA'  # 单币种多空点查看
# ==========> 因子排名相关额外参数配置(因子排名绘制的因子和子图1相同) <==========
rise_fall_factor = 'RiseFallRank'  # 用于表示涨跌幅榜的因子，因子计算如close.pct_change(n)
hold_period = 100  # 期望的根据换手率计算得到的持币时长(hour)
top_n = 10
filter_before_params = [  # 选币过滤条件
    ['df1', '涨跌幅max_fl_24', 'value', 'lte', 0.2, RankAscending.FALSE, FilterAfter.FALSE],
    ['df2', '涨跌幅max_fl_24', 'value', 'lte', 0.2, RankAscending.FALSE, FilterAfter.FALSE],
    ['df1', 'Volume_fl_24', 'rank', 'lte', 60, RankAscending.FALSE, FilterAfter.FALSE],
    ['df2', 'Volume_fl_24', 'rank', 'lte', 60, RankAscending.FALSE, FilterAfter.FALSE],
]


if __name__ == '__main__':
    # 测试
    f1_TopN_analysis(start_time, end_time, compound_name, factor, factor_param, time_interval, top,
                     if_cumulative_top=False, if_draw=False, if_copy_factor=False, extra_save_suffix="")
    f1_single_symbol_analysis(start_time, end_time, compound_name, factor, factor_param, time_interval,
                              symbol, if_copy_factor=False, extra_save_suffix="", is_draw_rank=True)
    f1_long_short_analysis(start_time, end_time, compound_name, factor, factor_param, time_interval)
    # 涨跌幅榜测试
    get_and_output_rise_fall_symbols(start_time, end_time, rise_fall_factor, hold_period, 10, filter_before_params,
                                     os.path.join(root_path, 'data', '回测结果'))
